<template>


<!--    </el-form-item>-->
<!--  </el-form>-->
<!--  <div id="content">-->
<!--    <p id="whereami">-->
<!--    </p>-->
<!--    <h1>修改页面</h1>-->
<!--    <el-form :model="users" ref="users" label-width="100px" class="demo-ruleForm" size="mini">-->
<!--      <el-form-item label="姓名" prop="username" :rules="[-->
<!--              { required: true, message: '姓名不能为空'},-->
<!--              { pattern: /^[\u4E00-\u9FA5]+$/, message: '姓名必须为汉字'}, ]">-->
<!--        <el-input type="name" v-model="users.username" autocomplete="off" style="width: 200px;"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="工资" prop="salary" :rules="[-->
<!--              { required: true, message: '工资不能为空'},-->
<!--              { type: 'number', message: '工资必须为数字值'},-->
<!--               ]">-->
<!--        <el-input type="salary" v-model.number="users.salary" autocomplete="off" style="width: 200px;"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="年龄" prop="age" :rules="[-->
<!--              { required: true, message: '年龄不能为空'},-->
<!--              { type: 'number', message: '年龄必须为数字值'},-->
<!--               ]">-->
<!--        <el-input type="age" v-model.number="users.age" autocomplete="off" style="width: 200px;"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" @click="submit('users')">提交</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->
<!--  </div>-->
<!--  <Yemian age={{age}} salary={{salary}} username={{username}}></Yemian>-->

  <div>
    <el-main>
      <yemian :formName="users" @handleSubmit="update" fromURL="update"></yemian>
    </el-main>
  </div>

</template>

<script>
import Yemian from '@/components/Yemian.vue'
export default {
  name: "Update",

  component: {
    'yemian': Yemian
  },
  created() {
    this.name=this.$route.query.name,
    this.salary=this.$route.query.salary,
    this.age= this.$route.query.age,
    this.id= this.$route.query.id,
    this.index=this.$route.query.index


    // console.log(this.name,111)
    // console.log(this.salary,222)
    // console.log(this.age,333)
    // console.log(this.id,111)
    // let tableData_json1 = localStorage.getItem('tableData_json')
    // this.tableData = JSON.parse(tableData_json1)
    // console.log(this.tableDate,878799)
    // this.users = this.tableData[this.index]
    // console.log(this.users,999)
  },
  data: function () {
    return {
      // row:this.$route.params.row,
      // index:this.$route.params.index
      // name: this.$route.params.row.name,
      // salary: this.$route.params.row.salary,
      // age: this.$route.params.row.age,
      // id: this.$route.params.row.id,
      // index: this.$route.params.index,

      users: {
        name: this.$route.query.name,
        salary: parseInt(this.$route.query.salary),
        age: parseInt(this.$route.query.age),
        id: parseInt(this.$route.query.id),
        index: parseInt(this.$route.query.index),
      }
    }
  },

  methods: {

      update: function (formName) {

        // this.$store.commit('updateems', formName)
        this.$store.commit('updateems', {'formName':formName,'index':this.index})
        this.$router.push({
          name: 'Ems',
        })

        // let tableData_json1 = localStorage.getItem('tableData_json')
        // let tableData = JSON.parse(tableData_json1)
        // tableData.splice(this.index,1,formName)
        //
        // let tableData_json = JSON.stringify(tableData)
        // localStorage.setItem('tableData_json',tableData_json)
        // this.$router.push({
        //         name: 'Ems',
        //       })
      }

      // this.$refs[formName].validate((valid) => {
      //   if (valid) {
      //     let tableData_json1 = localStorage.getItem('tableData_json')
      //     //反序列化为对象
      //     let tableData = JSON.parse(tableData_json1)
      //     // let tableData=[]
      //     //删掉对应的元素
      //     tableData.splice(this.index,1)
      //     //再添加已达到修改的效果
      //     let upda={
      //       id: this.users.id,
      //       name: this.users.username,
      //       salary: this.users.salary,
      //       age: this.users.age
      //     }
      //     tableData.splice(this.index, 0,upda)
      //
      //
      //     let tableData_json = JSON.stringify(tableData)
      //     localStorage.setItem('tableData_json',tableData_json)
      //
      //     this.$router.push({
      //       name: 'Ems',
      //     })
      //   }
      //   else {
      //
      //     return false;
      //   }
      // });

    },
  components: {
    Yemian
  }
}
</script>

<style scoped>

</style>